// pages/presentAccount/presentAccount.js+
var maxW = wx.getSystemInfoSync().windowWidth;
var maxH = wx.getSystemInfoSync().windowHeight;
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bankList:[],
    searchImg: '/images/add1.png',
    x: maxW - 30,
    y: maxH - 100,
    _type:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBank();
  },


  // 删除
  delcard:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    console.log(id)
    wx.showModal({
      title: '提示',
      content: '是否删除该账户',
      success: function (res) {
        if (res.confirm) {
          app.ajax({
            url:"Partner/Bank/delBank",
            data:{
              "bank_id":id
            },
            success:function(res){
                if(res.data.code == 1000){
                  wx.showToast({
                    title: res.data.message,
                    icon: 'none',
                    duration: 2000
                  })
                  that.setData({
                    bankList: []
                  })
                  that.getBank();
                }else{
                  wx.showToast({
                    title: res.data.message,
                    icon: 'none',
                    duration: 2000
                  })
                }
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 编辑
  eidtcard:function(e){
    console.log(e.currentTarget.dataset);
    var bank_id = e.currentTarget.dataset.id;
    // var types = e.currentTarget.dataset.type;
   wx.navigateTo({
     url: '../addeditAccount/addeditAccount?type=1&&bank_id=' + bank_id,
     success: function(res) {},
     fail: function(res) {},
     complete: function(res) {},
   })
  },

  // 添加账户
  addAccount:function(){
    wx.navigateTo({
      url: '../addeditAccount/addeditAccount?type=2',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //银行账户
  getBank:function(){
    var that = this;
    app.ajax({
      url:"Partner/Bank/getBankList",
      data:{},
      success:function(res){
        if(res.data.code == 1000){
            that.setData({
              bankList:res.data.data
            })
        }
      }
    })
  }
  
})